package com.mgxy.GlodMiner;

import java.awt.*;
import java.net.URL;

public class Bg {

    //关卡 和 得分
    static int level = 1;
    int goal = level * 5;
    //关卡开始时间和结束事件
    long startTime;
    long endTime;
    //总分
    static int count=0;
    //药水数量
    static int waterNum = 3;
    //药水状态 默认是false
    static  boolean waterFlag = false;
    //药水价格
    int price = (int) (Math.random()*10);
    //是否进入商店 f 不购买
    boolean shop = false;


    //载入图片
    Image bg = Toolkit.getDefaultToolkit().getImage(Bg.class.getClassLoader().getResource("resources/bg.jpg"));
    Image sky = Toolkit.getDefaultToolkit().getImage(Bg.class.getClassLoader().getResource("resources/sky.jpg"));
    Image peo = Toolkit.getDefaultToolkit().getImage(Bg.class.getClassLoader().getResource("resources/peo.png"));
    Image water = Toolkit.getDefaultToolkit().getImage(Bg.class.getClassLoader().getResource("resources/water.png"));

    //绘制
    void paintSelf(Graphics g) {
        g.drawImage(bg,0,200,null);
        g.drawImage(sky,0,0,null);
        drawWord(g,18,Color.blue,"Create By MG斜阳",520,180);
        switch (GameWin.gamestate){
            case 0:
                drawWord(g,50,Color.YELLOW,"点击鼠标右键开始游戏",150,500);
                break;
            case 1:
                g.drawImage(peo,310,50,null);
                drawWord(g,30,Color.BLACK,"积分:"+count,30,150);
                //药水控件
                g.drawImage(water,450,60,null);
                drawWord(g,30,Color.BLACK,"*"+waterNum,510,70);
                //关卡绘制 目标积分
                drawWord(g,20,Color.BLACK,"第"+level+"关",30,60);
                drawWord(g,30,Color.BLACK,"目标积分:"+goal,30,110);
                //时间
                endTime = System.currentTimeMillis();
                long tim = 20-(endTime-startTime)/1000;
                drawWord(g,30,Color.BLACK,"时间:"+(tim>0?tim:0),520,150);
                break;
            case 2:
                g.drawImage(water,300,400,null);
                drawWord(g,30,Color.black,"价格:"+price,300,500);
                drawWord(g,30,Color.black,"是否购买?",300,550);
                if(shop){
                    count = count-price;
                    waterNum++;
                    shop=false;
                    GameWin.gamestate=1;
                    startTime=System.currentTimeMillis();
                }
                break;
            case 3:
                drawWord(g,80,Color.cyan,"失败",250,350);
                drawWord(g,80,Color.cyan,"积分:"+count,200,450);
                break;
            case 4:
                drawWord(g,80,Color.red,"成功",250,350);
                drawWord(g,80,Color.red,"积分:"+count,200,450);
                break;
            default:
        }

    }

    //绘制字符串
    public static void drawWord(Graphics g,int size,Color color,String s,int x,int y){
        g.setColor(color);
        g.setFont(new Font("仿宋",Font.BOLD,size));
        g.drawString(s,x,y);
    }


    //t倒计时完成 f正在倒计时
    boolean gameTime(){
        long tim = (endTime-startTime)/1000;
        if(tim>20){return true;}
        return false;

    }

    //重置元素
    void reGameBg(){
        //关卡数
        level = 1;
        //目标得分
        goal = level*15;
        //总分
        count=0;
        //药水数量
        waterNum = 3;
        //药水状态,默认F,T 正在使用 F 无法使用
        waterFlag = false;
    }
}


